package com.fr.lintcode;

public class Q1667 {

    /**
     * @param arr: the 01 array
     * @param k: the limit 
     * @return: the sum of the interval
     */
    public long intervalStatistics(int[] arr, int k) {
        // Write your code here.
    	long count = 0;
    	if(arr == null || arr.length == 0) {
    		return count;
    	}
    	for(int i = 0; i < arr.length; i++) {
    		if(arr[i] != 0) {
    			continue;
    		}
    		int one = 0;
    		for(int j = i; j < arr.length; j++) {
    			if(arr[j] == 0) {
    				if(one <= k) {
    					count++;
    				}else {
    					break;
    				}
    			}else if(arr[j] == 1){
    				one ++;
    				if(one > k) {
    					break;
    				}
    			}
    		}
    	}
    	return count;
    }


}
